package cn.tju.yanbo.datechoose;

import java.sql.Date;
import java.util.Calendar;
import java.util.Random;

import org.w3c.dom.Document;

import cn.tju.yanbo.commons.BaseActivity;
import cn.tju.yanbo.commons.CalendarGestureListener;
import cn.tju.yanbo.commons.db.AppDatabase;

import cn.tju.yanbo.R;
import cn.tju.yanbo.calendar.LunarCalendarActivity;
import cn.tju.yanbo.goodoccasion.GoodOccasionActivity;
import cn.tju.yanbo.homepage.HomepageActivity;
import cn.tju.yanbo.luckyday.LuckyDayActivity;
import cn.tju.yanbo.setting.SettingActivity;
import cn.tju.yanbo.utils.AppConfig;
import cn.tju.yanbo.utils.AppUtils;
import cn.tju.yanbo.utils.LocationUtils;
import cn.tju.yanbo.weather.WeatherUtils;

import android.graphics.Point;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.TextView;

public class DateChooseActivity extends BaseActivity {
    /** Called when the activity is first created. */
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.choose_date);

        this.update(Calendar.getInstance());
        this.initActivity(savedInstanceState);
        
        View view = findViewById(R.id.main_content_view);
        view.setOnTouchListener(new CalendarGestureListener(this));
    }

    protected void registerIntent() {
        registerIntent(R.id.menu_homepage, HomepageActivity.class);
        registerIntent(R.id.menu_lunar_calendar, LunarCalendarActivity.class);
        registerIntent(R.id.menu_good_occasion, GoodOccasionActivity.class);
        registerIntent(R.id.menu_lucky_day, LuckyDayActivity.class);
        registerIntent(R.id.menu_setting, SettingActivity.class);
    }

    @Override
    protected boolean hasDateView() {
        return true;
    }

    @Override
    protected Class<?> leftActivity() {
        return LunarCalendarActivity.class;
    }

    @Override
    protected Class<?> rightActivity() {
        return GoodOccasionActivity.class;
    }

    @Override
    protected Drawable background() {
        return CACHED_PICTURES.get(R.drawable.choose_date);
    }
    
    public void update(Calendar c) {
        String sc = AppUtils.format("yyyy-MM-dd", c.getTime());
        Date date = Date.valueOf(sc);
        
        Random random = new Random(date.getTime());
        
        String yiLeftUpPic = AppConfig.YIJI_PIC_NAMES[Math.abs(random.nextInt())%AppConfig.YIJI_PIC_TOTAL];
        String yiLeftBotPic = AppConfig.YIJI_PIC_NAMES[Math.abs(random.nextInt())%AppConfig.YIJI_PIC_TOTAL];
        String yiRightUpPic = AppConfig.YIJI_PIC_NAMES[Math.abs(random.nextInt())%AppConfig.YIJI_PIC_TOTAL];
        String yiRightBotPic = AppConfig.YIJI_PIC_NAMES[Math.abs(random.nextInt())%AppConfig.YIJI_PIC_TOTAL];
        String jiLeftUpPic = AppConfig.YIJI_PIC_NAMES[Math.abs(random.nextInt())%AppConfig.YIJI_PIC_TOTAL];
        String jiLeftBotPic = AppConfig.YIJI_PIC_NAMES[Math.abs(random.nextInt())%AppConfig.YIJI_PIC_TOTAL];
        String jiRightUpPic = AppConfig.YIJI_PIC_NAMES[Math.abs(random.nextInt())%AppConfig.YIJI_PIC_TOTAL];
        String jiRightBotPic = AppConfig.YIJI_PIC_NAMES[Math.abs(random.nextInt())%AppConfig.YIJI_PIC_TOTAL];
        
        ImageView yiLeftUpView = (ImageView)this.findViewById(R.id.yi_pic_left_up);
        ImageView yiLeftBotView = (ImageView)this.findViewById(R.id.yi_pic_left_bottom);
        ImageView yiRightUpView = (ImageView)this.findViewById(R.id.yi_pic_right_up);
        ImageView yiRightBotView = (ImageView)this.findViewById(R.id.yi_pic_right_bottom);
        ImageView jiLeftUpView = (ImageView)this.findViewById(R.id.ji_pic_left_up);
        ImageView jiLeftBotView = (ImageView)this.findViewById(R.id.ji_pic_left_bottom);
        ImageView jiRightUpView = (ImageView)this.findViewById(R.id.ji_pic_right_up);
        ImageView jiRightBotView = (ImageView)this.findViewById(R.id.ji_pic_right_bottom);
        
        yiLeftUpView.setImageDrawable(CACHED_PICTURES.get("yi_"+yiLeftUpPic));
        yiLeftBotView.setImageDrawable(CACHED_PICTURES.get("yi_"+yiLeftBotPic));
        yiRightUpView.setImageDrawable(CACHED_PICTURES.get("yi_"+yiRightUpPic));
        yiRightBotView.setImageDrawable(CACHED_PICTURES.get("yi_"+yiRightBotPic));
        
        jiLeftUpView.setImageDrawable(CACHED_PICTURES.get("ji_"+jiLeftUpPic));
        jiLeftBotView.setImageDrawable(CACHED_PICTURES.get("ji_"+jiLeftBotPic));
        jiRightUpView.setImageDrawable(CACHED_PICTURES.get("ji_"+jiRightUpPic));
        jiRightBotView.setImageDrawable(CACHED_PICTURES.get("ji_"+jiRightBotPic));
    }
}
